package com.nogroup.springbootproject.controller;


import com.nogroup.springbootproject.entity.Authority;
import com.nogroup.springbootproject.service.LoginService;
import com.nogroup.springbootproject.utils.result.DataResult;
import com.nogroup.springbootproject.utils.result.code.Code;
import com.nogroup.springbootproject.vo.LoginUserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("login")
@RestController
public class LoginController {
    @Autowired
    private LoginService loginService;


    @RequestMapping("login")
    public DataResult loginUser(@RequestBody Authority authority){
        LoginUserVo loginUserVo = loginService.loginUser(authority);
        if(null == loginUserVo){
            return DataResult.errByErrCode(Code.LOGIN_ERROR);
        }

        return DataResult.successByData(loginUserVo);
    }
}
